home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3171 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: class declaration question
  5. Date: 22 Jan 1996 16:44:18 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan22114418@g7240065.bridge.bst.bls.com>
  8. References: <4dphp6$1bp@noc2.drexel.edu> <4drakm$hnu@grid.direct.ca>
  9. NNTP-Posting-Host: bstfirewall.bst.bls.com
  10. In-reply-to: qjackson@direct.ca's message of Sat, 20 Jan 1996 18:02:09 GMT
  11.  
  12. In article <4drakm$hnu@grid.direct.ca> qjackson@direct.ca writes:
  13.  
  14. : st918h5w@dunx1.ocs.drexel.edu (Jonathan Juniman) wrote:
  15.  
  16. :> Is it necessary to do this:
  17.  
  18. :> class SomeClass
  19. :>     {
  20. :>     public:
  21. :>     void Somefunction(int SomeParameter);
  22. :>     }
  23.  
  24. :> or is it just as legal to do this:
  25. :> class SomeClass
  26. :>     {
  27. :>     public:
  28. :>     void SomeFunction(int);
  29. :>     }
  30.  
  31. :> The latter seems to be the convention, but why does the compiler need to
  32. :> know the name of SomeFunction's argument?  Isn't it sufficient to know the
  33. :> type of Somefunction's argument (namely, int)?  
  34.  
  35. Both are valid. And neither one more valid than the other for the compiler.
  36. The compiler does not need to know the name of the parameter
  37. but a fellow programmer who decides to use your class might. Not only is
  38. the code for a compiler to generate 1's and 0's from but it also to
  39. communicate with fellow programmers and sensibly named parameters can
  40. go a long way to informing other programmers what exactly the parameter
  41. is for.
  42.  
  43. : The following will compile under Turbo C++ 3.00 -- I don't know what
  44. : the standard is --
  45.  
  46. : class foo
  47. : {
  48. :     public:
  49. :     void bar (int);
  50. : };
  51.  
  52. : void foo::bar (int baz)
  53. : {
  54. :     // do someFoobar
  55. :     ++baz;
  56. : }
  57.  
  58. : void main (void)
  59. : {
  60. :     foo Chocolate;
  61. :     Chocolate.bar(10);
  62. : }
  63.  
  64. The following will compile but has undefined results when run.
  65. The standard says that
  66.  
  67.   void main(void)
  68.  
  69. has undefined behaviour and should be declared
  70.  
  71.   int main(void)
  72. or
  73.   int main(int argc, char* argv[])
  74.  
  75. Regards
  76.  
  77.   -A.
  78. -- 
  79. | A.Champion                |
  80.